package cn.maihe.elg.operation.supports.electronicseal.anne.service.impl;

import cn.maihe.elg.operation.config.AnneSignConfig;
import cn.maihe.elg.operation.config.ElgConfig;
import cn.maihe.elg.operation.supports.electronicseal.anne.AnneServiceName;
import cn.maihe.elg.operation.supports.electronicseal.anne.BaseAnneSignService;
import cn.maihe.elg.operation.supports.electronicseal.anne.bean.annesign.contract.ContractPreviewListRequest;
import cn.maihe.elg.operation.supports.electronicseal.anne.bean.annesign.contract.ContractPreviewListRequestBody;
import cn.maihe.elg.operation.supports.electronicseal.anne.bean.annesign.contract.ContractPreviewListResponse;
import cn.maihe.elg.operation.supports.electronicseal.anne.utils.annesign.ApiException;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description 合同预览地址
 * @Author WJH
 * @Date 2021/08/13
 */
@Slf4j
@Service
public class ContractPreViewService extends BaseAnneSignService<ContractPreviewListRequest, ContractPreviewListResponse> {


    public ContractPreViewService(AnneSignConfig anneSignConfig, ElgConfig elgConfig) {
        super(anneSignConfig, elgConfig);
    }

    @Override
    protected AnneServiceName serviceName() {
        return AnneServiceName.contract_preview;
    }


    /**
     * 合同预览
     *
     * @param anneSignContractId
     */
    public List<String> contractPreview(Long anneSignContractId) {
        ContractPreviewListRequest request = this.buildBaseReq();
        ContractPreviewListRequestBody body = new ContractPreviewListRequestBody();
        body.setContractIdList(Lists.newArrayList(anneSignContractId));
        body.setHighQuantity(true);
        body.setPdfImgSourceType("sign");

        request.setBody(body);

        ContractPreviewListResponse response = null;
        try {
            response = this.doPost(request);
        } catch (Exception e) {
            log.error("合同预览异常:{}", e.getMessage(), e);
            throw new ApiException("合同预览失败:" + e.getMessage(), e);
        }

        return response.getBody().getPreviewImgUriList();
    }


}
